import pickle
import time
import warnings
from easy_instance_labeling import EasyInstanceLabeling
from gml import  GML
from gml_utils import *


if __name__ == '__main__':
    warnings.filterwarnings('ignore')  # 过滤掉warning输出
    begin_time = time.time()
    dataname = "dblp"
    with open('testdata/'+dataname+'_variables.pkl', 'rb') as v:
        variables = pickle.load(v)
    with open('testdata/'+dataname+'_features.pkl', 'rb') as f:
        features = pickle.load(f)
    #防止数据中错误
    for variable in variables:
        variable['is_evidence'] = False
        variable['is_easy'] = False
    easys = load_easy_instance_from_file('testdata/'+dataname+'_easys.csv')
    EasyInstanceLabeling(variables, features, easys).label_easy_by_file()
    #适用于ER
    graph = GML(
        dataname,
        variables,
        features,
        evidential_support_method='regression',
        approximate_probability_method='interval',
        evidence_select_method='interval',
        construct_subgraph_method='unaryPara',
        top_m=2000,
        top_k=10,
        update_proportion= 0.01,
        balance = False,
        optimization = True
    )
    #适用于ALSA
    # graph = GML(
    #     dataname,
    #     variables,
    #     features,
    #     evidential_support_method='relation',
    #     approximate_probability_method='relation',
    #     evidence_select_method='relation',
    #     construct_subgraph_method='mixture',
    #     top_m=20,
    #     top_k=3,
    #     update_proportion= -1,
    #     balance = False,
    #     optimization = False
    # )
    graph.inference()
    graph.score()
    end_time = time.time()
    print('Running time: %s Seconds' % (end_time - begin_time))